/** 消息通知表 */
module.exports = (sequelize, Sequelize) => {
    return sequelize.define('pure_notices', {
        id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
        from_user: {
            type: Sequelize.INTEGER,
            allowNull: false,
            comment: '来自用户ID',
        },
        to_user: {
            type: Sequelize.INTEGER,
            allowNull: false,
            comment: '发送给用户ID',
        },
        title: {
            type: Sequelize.STRING(200),
            allowNull: false,
            comment: '消息标题',
        },
        subtitle: {
            type: Sequelize.STRING(200),
            comment: '消息副标题',
        },
        type: {
            type: Sequelize.INTEGER,
            allowNull: false,
            comment: '消息分类 1:消息通知 2:系统公告',
        },
        status: {
            type: Sequelize.INTEGER,
            comment: '消息类型 0:primary 1:success 2:warning 3:info 4:danger',
            defaultValue: 0,
            get() {
                const val = this.getDataValue('status');
                if (!val) return 'primary'
                switch (val) {
                    case 1:
                        return 'success'
                    case 2:
                        return 'warning'
                    case 3:
                        return 'info'
                    case 4:
                        return 'danger'
                }
            },
            set(val) {
                switch (val) {
                    case 'success':
                        this.setDataValue('status', 1);
                        break;
                    case 'warning':
                        this.setDataValue('status', 2);
                        break;
                    case 'info':
                        this.setDataValue('status', 3);
                        break;
                    case 'danger':
                        this.setDataValue('status', 4);
                        break;
                    default: this.setDataValue('status', 0);
                }
            },
        },
        content: {
            type: Sequelize.STRING(250),
            comment: '消息内容',
        },
        read: {
            type: Sequelize.BOOLEAN,
            defaultValue: 0,
            comment: '是否已读 0:未读 1:已读',
        },
        path: {
            type: Sequelize.STRING,
            comment: '消息链接',
        },
        spare1: {
            type: Sequelize.STRING(50),
            notNull: true,
            comment: '备用字段',
        },
        spare2: {
            type: Sequelize.STRING(50),
            notNull: true,
            comment: '备用字段',
        },
    }, {
        comment: '消息通知表',
        updatedAt: false,
    })

}